package com.briup.jz.web.controller;

import com.briup.jz.bean.RolePrivilege;
import com.briup.jz.bean.extend.RolePrivilegeExtend;
import com.briup.jz.service.IRolePrivilegeService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: jz
 * @description: 角色权限控制器
 * @author: catmilko
 * @create: 2020/6/12 15:51
 **/

@RestController
@RequestMapping("/rolePrivilege")
@Api(description = "角色权限管理接口")
public class RolePrivilegeController {
@Autowired
private IRolePrivilegeService rolePrivilegeService;

    @ApiOperation(value = "查询所有角色权限")
    @GetMapping("findAll")
    public Message findAll() {
        List<RolePrivilege> list = rolePrivilegeService.findAll();
        return MessageUtil.success(list);
    }


    @ApiOperation(value = "通过id查询角色权限")
    @ApiImplicitParam(name = "id", value = "类别唯一编号", required = true, paramType = "query")
    @GetMapping("findById")
    public Message findById(long id) {
        RolePrivilege rolePrivilege = rolePrivilegeService.findById(id);
        return MessageUtil.success(rolePrivilege);
    }

    @ApiOperation(value = "保存或通过id更新角色权限")
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(RolePrivilege rolePrivilege) {
        rolePrivilegeService.saveOrUpdate(rolePrivilege);
        return MessageUtil.success("保存成功");
    }

    @ApiOperation(value = "通过id删除角色权限")
    @ApiImplicitParam(name = "id", value = "类别唯一编号", required = true, paramType = "query")
    @GetMapping("deleteById")
    public Message deleteById(long id) {
        rolePrivilegeService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "查询角色权限+角色+权限信息")
    @GetMapping("findAllWithRoleAndPrivilege")
    public Message findAllWithRoleAndPrivilege() {
        List<RolePrivilegeExtend> list = rolePrivilegeService.findAllWithRoleAndPrivilege();
        return MessageUtil.success(list);
    }
}
